在添加貨刪除時有更多控制的資料結構
// 建立類別
function Stack(){
var items = [];
this.push = function(element){
items.push(element);
}
this.pop = function(element){
items.pop(element);
}
this.peep = function(element){
return items[items.length -1];
}
this.isEmpty = function(){
return items.length == 0;
}
this.size = function(){
return items.length ;
}
this.clear = function(){
return items= [] ;
}
this.print = function(){
console.log(items.toString());
}
}
// 使用類別
const stack = new Stack()